package com.weixin.junit;

import java.text.ParseException;

import org.quartz.CronExpression;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author Administrator
 *
 */
public class Quartz {
    //创建调度器
    public static Scheduler getScheduler() throws SchedulerException{
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        return schedulerFactory.getScheduler();
    }
	 public static void schedulerJob() throws SchedulerException, ParseException{
	        //创建任务
		    String jobName = "what21.com";
	        // 任务组
	        String jobGroup = "what21.com";
	         
	        // 构建JobDetail
	        JobDetail jobDetail= JobBuilder.newJob(MyJob.class)
	                .withIdentity(jobName,jobGroup)
	                .build();
	 
	        // 触发名称
	        String triName = "what21.com";
	        // 出发表达式
	        String triPress = "* * 16 ? * *";
	        CronExpression express;
			
		    express = new CronExpression(triPress);
			
	
	        // 构建触发器
	        Trigger trigger= TriggerBuilder.newTrigger()
	                .withIdentity(triName,jobGroup)
	                .startNow()
	                .withSchedule(CronScheduleBuilder.cronSchedule(express))
	                .build();
	         
	        // 创建调度器（Scheduler）
	        SchedulerFactory sf = new StdSchedulerFactory();
	        Scheduler sched = sf.getScheduler();
	         
	        // 注册调度器（Scheduler）
	        sched.scheduleJob(jobDetail,trigger);
	         
	        // 启动调度器（Scheduler）
	        sched.start();
	        
	    }
	public void cron(){
	    System.out.println(1);
	    }

    public static void main(String[] args) throws SchedulerException, InterruptedException, ParseException {
    
    	//Quartz.schedulerJob();
    }
}